export default class WallControl extends Laya.Script3D {
    /** 初始局部坐标位置*/
    private originLocalPos: Laya.Vector3;
    /** 墙向上移动的距离*/
    private moveYDis: number = 25;
    /** 新的向上移动的距离值  如果序列化 设置了值 就用这个 不然就用原来的*/
    public moveYDisNew: number = 0;
    /** 向上移动的目标Y值*/
    private upTargetY: number;
    /** 移动tween*/
    moveTween: Laya.Tween;

    private mowner: Laya.Sprite3D;

    onAwake() {
        this.mowner = this.owner as Laya.Sprite3D;
        this.originLocalPos= this.mowner.transform.localPosition.clone();
        if (this.moveYDisNew != 0) {
            this.moveYDis = this.moveYDisNew;
        }
        this.upTargetY = this.originLocalPos.y + this.moveYDis;
    }

    /** 向上移动*/
    public MoveUp(): void {
        this.moveTween = Laya.Tween.to(this.mowner.transform, { localPositionY: this.upTargetY }, 500, null, Laya.Handler.create(this, () => {
            this.mowner.active = false;

        }));
    }

    /** 向下移动*/
    public MoveDown(): void {
        this.mowner.active = true;
        this.moveTween = Laya.Tween.to(this.mowner.transform, { localPositionY: this.originLocalPos.y }, 500, null, Laya.Handler.create(this, () => {
            this.mowner.transform.localPosition = this.originLocalPos.clone();
        }));
    }

    /** 直接移动到上面*/
    public SetUpPos(): void {
        let targetPos = new Laya.Vector3(0, 0, 0);
        Laya.Vector3.add(this.originLocalPos, new Laya.Vector3(0, this.moveYDis, 0), targetPos);
        this.mowner.transform.localPosition = targetPos.clone();
        this.mowner.active = false;
    }

    /** 直接移动下来*/
    public SetDownPos(): void {
        this.mowner.transform.localPosition = this.originLocalPos.clone();
        this.mowner.active = true;
    }
}